package com.csx.base.design.structure.proxy.staticM;

import com.csx.base.design.structure.proxy.Internet;
import com.csx.base.design.structure.proxy.Modem;

import java.util.Arrays;
import java.util.List;

/**
 * @author cuisongxu
 * @date 2022/9/22 12:08
 */
public class RouterProxy implements Internet {

    private final String PASSWORD = "123456";
    /**
     * 被代理对象
     */
    private Internet modem;

    private List<String> blackList = Arrays.asList("电影", "游戏", "音乐", "小说");

    public RouterProxy() throws Exception {
        this.modem = new Modem(PASSWORD);
    }

    @Override
    public void httpAccess(String url) {
        for (String keyword : blackList) {
            // 包含黑名单中的字样
            if(url.contains(keyword)) {
                System.out.println("禁止访问: " + url);
                return;
            }
        }
        modem.httpAccess(url);
    }
}
